from django.shortcuts import render
from app01 import models


# Create your views here.


def article(request, *args, **kwargs):
    print(kwargs)
    print(request.path_info)  # 获取当前URL
    from django.urls import reverse
    url = reverse('article', kwargs=kwargs)
    print(url)
    condition = {}
    for k, v in kwargs.items():
        kwargs[k] = int(v)
        if v == '0':
            pass
        else:
            condition[k] = v
    article_list = models.Article.objects.filter(**condition)
    article_type_list = models.ArticleType.objects.all()
    category_list = models.Category.objects.all()
    return render(request, 'article.html', {'article_list': article_list,
                                            'article_type_list': article_type_list,
                                            'category_list': category_list,
                                            'arg_dict': kwargs},
                  )


def article_simple(request, *args, **kwargs):
    print(kwargs)
    print(request.path_info)  # 获取当前URL
    from django.urls import reverse
    url = reverse('article', kwargs=kwargs)
    print(url)
    condition = {}
    for k, v in kwargs.items():
        kwargs[k] = int(v)
        if v == '0':
            pass
        else:
            condition[k] = v
    article_list = models.Article.objects.filter(**condition)
    article_type_list = models.ArticleType.objects.all()
    category_list = models.Category.objects.all()
    return render(request, 'article-simple.html', {'article_list': article_list,
                                                   'article_type_list': article_type_list,
                                                   'category_list': category_list,
                                                   'arg_dict': kwargs},
                  )
